<template>
	<view>
		<!-- 用户模块 -->
		<view>
			<view class="user_box">
				<u-avatar v-if="userInfo.avatarUrl" :src="userInfo.avatarUrl"></u-avatar>
				<u-avatar v-else src="/static/icons/avatar.png"></u-avatar>
				<view v-if="userInfo.nickName" class="username">{{userInfo.nickName}}</view>
				<navigator v-else url="/pages/login/login" class="username">
					<view>立即登录</view>
					<text>登录后可收藏喜欢的菜谱</text>
				</navigator>
			</view>
		</view>

		<view class="viptemplate" @click="open">
			<image src="/static/images/viptemplate.png" mode="widthFix"></image>
			<text class="updataText">升级为VIP</text>
		</view>
		<myfunction :userInfo="userInfo"></myfunction>
		<mytabs></mytabs>
		<!-- 我的菜谱 -->
		<view class="mycook">
			<text>我的菜谱</text>
			<view class="cook_list">
				<view class="cook_item" v-for="item in cookData" :key="item">
					<image :src="item.image" mode=""></image>
					<text>{{item.name}}</text>
				</view>
			</view>
		</view>
		<!-- footer -->
		<view class="footer">
			<view class="footer_box">
				<image src="/static/icons/praise.png" mode=""></image>
				<text>去App Store给菜谱大全评分</text>
			</view>
			<view class="footer_box">
				<image src="/static/icons/message.png" mode=""></image>
				<text>反馈问题</text>
			</view>
		</view>
		<u-modal v-model="show" :content="content" @confirm="confirm" :show-cancel-button="true"></u-modal>
		<view v-if="userInfo" class="sign_out" @click="this.show = true">
			<button type="primary">退出登录</button>
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				userInfo: null,
				cookData: [{
						name: "蜜豆鲷鱼烧",
						image: "/static/images/midoudiaoyushao.png"
					},
					{
						name: "川北凉粉",
						image: "/static/images/chuanbeiliangfen.png"
					},
					{
						name: "牛肉披萨",
						image: "/static/images/niuroupisa.png"
					},
					{
						name: "奶油泡芙",
						image: "/static/images/naiyoupaofu.png"
					},
				],
				show: false,
				content: '你确定要退出？',
			}
		},
		methods: {
			// 开通会员
			open() {
				uni.navigateTo({
					url: '/pages/member/openMember'
				})
			},
			confirm() {
				this.userInfo = null;
				getApp().globalData.userInfo = null;
				uni.removeStorage({
					key: 'token'
				});
			}
		},
		onShow: function() {
			this.userInfo = getApp().globalData.userInfo;
		}
	}
</script>

<style lang="scss">
	page {
		background: #f5f5f5;
	}

	.user_box {
		position: relative;
		width: 700rpx;
		margin: 0 auto;
		background: #fff;
		align-items: center;
		display: flex;

		.username {
			margin-left: 30rpx;

			>view {
				font-size: 28rpx;
			}

			>text {
				font-size: 24rpx;
				color: #ccc;
			}
		}

		&::before {
			content: '';
			width: 10rpx;
			height: 10rpx;
			border-top: 2px solid #ccc;
			border-right: 2px solid #ccc;
			position: absolute;
			top: 50%;
			right: 0;
			transform-origin: center;
			transform: rotateZ(45deg);
		}
	}

	.viptemplate {
		position: relative;
		padding: 30rpx;
		background: #fff;

		>image {
			width: 100%;
		}

		.updataText {
			position: absolute;
			top: 20%;
			left: 15%;
			width: 550rpx;
			display: block;
			color: #DA7B36;

			&::before {
				content: '';
				width: 10rpx;
				height: 10rpx;
				border-top: 2px solid #ccc;
				border-right: 2px solid #ccc;
				position: absolute;
				top: 50%;
				right: 0;
				transform-origin: center;
				transform: rotateZ(45deg);
			}
		}
	}

	.mycook {
		background: #FFFFFF;
		margin: 20rpx 0;

		text {
			padding: 0 20rpx;
		}

		.cook_list {
			display: flex;
			overflow: auto;

			.cook_item {
				>image {
					margin: 20rpx;
					width: 180rpx;
					height: 200rpx;
				}
			}
		}
	}

	.footer {
		margin-bottom: 20rpx;

		.footer_box {
			position: relative;
			padding: 0 20rpx;
			height: 80rpx;
			background: #fff;
			align-items: center;
			display: flex;

			>image {
				width: 50rpx;
				height: 50rpx;
				margin-right: 20rpx;
			}

			&::before {
				content: '';
				width: 10rpx;
				height: 10rpx;
				border-top: 2px solid #ccc;
				border-right: 2px solid #ccc;
				position: absolute;
				top: 50%;
				right: 5%;
				transform-origin: center;
				transform: rotateZ(45deg);
			}

		}
	}

	.sign_out {
		width: 500rpx;
		margin: 30rpx auto;
	}
</style>
